package pers.wensheng.patterns.behavioral_pattern.chain_responsibility_pattern.entity;

import lombok.Getter;
import lombok.Setter;
import pers.wensheng.patterns.behavioral_pattern.chain_responsibility_pattern.LeaveRequest;

/**
 *  抽象处理者
 */
public abstract class Handler {

    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    /**
     * 该领导处理的请假天数区间
     */
    private int numStart;
    private int numEnd;

    /**
     * 声名后继者（或声名上级领导）
     */
    @Getter
    @Setter
    private Handler netxHandler;

    /**
     * --------------构造方法------------------
     */

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    /**
     * 各级领导处理请假条的方法
     * @param leave
     */
    protected abstract void handlerLeave(LeaveRequest leave);
    /**
     * 提交请假条
     */
    public final void submit(LeaveRequest leave){
        if (leave.getNumber() <= numEnd){
            this.handlerLeave(leave);
        }

        if (this.netxHandler != null && leave.getNumber() > this.numEnd ){
            //提交上级领导审批
            netxHandler.submit(leave);
        }else {
            System.out.println("流程结束！");
        }
    }
}
